image: karimovav/autotests_project_growth:latest

variables:
  ALLURE_ENDPOINT: https://karimov3266.testops.cloud/
  ALLURE_PROJECT_ID: 1
  ALLURE_RESULTS: build/allure-results
  TEST_PATH:
    value: "tests"
    description: "Переменая для указания директории с тестами"
  TEST_ENV:
    value: "dev"
  OS:
    value: "linux"
  RUNNER_TAG:
    value: "gitlab-org"
  NUMBER_P:
    value: "100"
  NUMBER_S:
    value: "200"
  SCRIPT_TEST:
    value: "echo $NUMBER_P"

workflow:
  rules:
    - if: $OS == "windows"
      variables:
        RUNNER_TAG: "windows"
    - if: $TEST_ENV == "prod"
      variables:
        SCRIPT_TEST: "echo $NUMBER_S"
    - when: always

stages:
  - script_job
  - testing
  - send_report

#  +------------------------------------------------------------------------------------------+
# | Установка зависимостей, библиотек, прогонка тестов и сохранения результатов в артифактах |
# +------------------------------------------------------------------------------------------+

#script_job:
#  tags:
#    - $RUNNER_TAG
#  stage: script_job
#  script:
#    - $SCRIPT_TEST
#  allow_failure: true

testing_job:
  tags:
    - $RUNNER_TAG
  stage: testing
  script:
    - 'pytest $TEST_PATH --alluredir=./$ALLURE_RESULTS'
  allow_failure: true
  artifacts:
    when: always
    paths:
      - ./$ALLURE_RESULTS
    expire_in: 1 week
  rules:
    - if: $TEST_ENV == "prod"

# +------------------------------------------------------------+
# | Генерация allure отчета на основе сохраненных результатов |
# +-----------------------------------------------------------+

allure_job:
  tags:
    - $RUNNER_TAG
  stage: send_report
  image: gradle
  before_script:
    - curl -fsSL https://github.com/allure-framework/allurectl/releases/latest/download/allurectl_linux_amd64 -o allurectl
    - chmod +x allurectl
  script:
    - ./allurectl watch -- gradle clean test
  artifacts:
    paths:
      - ./$ALLURE_RESULTS
      - ./allure-report
    expire_in: 1 day